package com.example.infowall02.config;

import com.example.infowall02.utils.UserLoginFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.example.infowall02.utils.AutoLoginFilter;

// 配置过滤器的配置类
@Configuration
public class FilterConfig {
    // 注册admin过滤器的 Bean
    @Bean
    public FilterRegistrationBean<AutoLoginFilter> autoLoginFilterRegistrationBean() {
        // 实例化过滤器
        FilterRegistrationBean<AutoLoginFilter> registrationBean = new FilterRegistrationBean<>();
        //设置过滤器的名称
        registrationBean.setFilter(new AutoLoginFilter());
        //设置过滤器的 URL 模式，这里设置为admin的相关路径,以及操作article的相关路径
        registrationBean.addUrlPatterns("/admin/*");
        //返回注册的过滤器 Bean
        return registrationBean;
    }
    // 注册user过滤器的 Bean
    @Bean
    public FilterRegistrationBean<UserLoginFilter> userLoginFilterFilterRegistrationBean() {
        // 实例化过滤器
        FilterRegistrationBean<UserLoginFilter> registrationBean = new FilterRegistrationBean<>();
        //设置过滤器的名称
        registrationBean.setFilter(new UserLoginFilter());
        //设置过滤器的 URL 模式，这里设置为user的相关路径
        registrationBean.addUrlPatterns("/user/*","/like/*","/favorite/*");
        return registrationBean;
    }
}